package main

import (
	"context"
	"fmt"
	"log"

	"gitee.com/go-course/go12/skills/grpc/hello"
	"google.golang.org/grpc"
	"google.golang.org/grpc/credentials/insecure"
)

func main() {
	// 1. grpc 客户端是自动生成好的

	// 1. grpc.Dial负责和gRPC服务建立链接
	conn, err := grpc.Dial("localhost:1234", grpc.WithTransportCredentials(insecure.NewCredentials()))
	if err != nil {
		log.Fatal(err)
	}
	defer conn.Close()

	// 2. 基于conn初始化一个客户端对象
	c := hello.NewHelloServiceClient(conn)
	resp, err := c.Hello(context.Background(), &hello.HelloRequest{Name: "bob"})
	if err != nil {
		panic(err)
	}
	fmt.Println(resp)
}
